﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using CSharp.Libs.WPF;
using System.Collections;

namespace CSharp.Libs.Koc.UserControls.ItemClasses
{

    public class ReportItem : ViewModelBase
    {
        #region declarations
        #endregion



        #region constructor / terminator
        public ReportItem(
            ReportListItem _RLI)
        {
            RLI = _RLI;
        }

        public ReportItem(
            ReportListItem RLI,
            Kernel KRNL,
            Hashtable htReportItem) : this (RLI)
        {
            Report = htReportItem;
        }
        #endregion



        #region private functions
        private int _getReportOffensiveTroopCount()
        {
            try
            {
                if (Report == null)
                {
                    return 0;
                }

                //get fight details
                Hashtable htFght = Report[constants.KEY_FGHT] as Hashtable;
                if (htFght != null)
                {
                    //get offensive troops (s1)
                    Hashtable htS1OffTroops = htFght["s1"] as Hashtable;
                    if (htS1OffTroops != null)
                    {
                        int TroopCount = 0;

                        foreach (DictionaryEntry DE in htS1OffTroops)
                        {
                            ArrayList aryValue = DE.Value as ArrayList;
                            if (aryValue != null)
                            {
                                int localCount = 0;
                                if (int.TryParse(aryValue[1].ToString(), out localCount))
                                {
                                    TroopCount += localCount;
                                }
                            }
                        }

                        return TroopCount;
                    }
                }
            }
            catch (Exception ex)
            {
                throw ex;
            }

            return -1;
        }
        #endregion



        #region interface
        #region properties
        public ReportListItem RLI { get; set; }

        public Hashtable Report { get; set; }
        #endregion

        #region methods
        public int GetReportOffensiveTroopCount()
        {
            return _getReportOffensiveTroopCount();
        }
        #endregion
        #endregion
    }
}
